'''
作者: 张海南
日期: 2025/4/1
用户: 27934
文件名: thread_demo.py
'''
import logging
import threading
import time
# 线程锁
from threading import Lock
lock=Lock()
def Log():
    logging.basicConfig(
        filename='log.txt',
        level=logging.INFO,
        filemode='w+',
        format='%(message)s'
    )

class testThread():

    def watchTV(self):
        for _ in range(10):
            with lock:
                logging.info('看电视')
                time.sleep(1)

    def QQchat(self):
        for _ in range(10):
            with lock:
                logging.info('QQ聊天')
                time.sleep(1)

    def do_homework(self):
        for _ in range(10):
            with lock:
                logging.info('做家务')
                time.sleep(1)

# 生成一个对象
threadobj=testThread()
# 调用采集日志
Log()
# 产生线程对象
print('开始时间：',time.asctime())
t1=threading.Thread(target=threadobj.watchTV)
t2=threading.Thread(target=threadobj.QQchat)
t3=threading.Thread(target=threadobj.do_homework)
t1.start()
t2.start()
t3.start()
t1.join()
t2.join()
t3.join()
print('结束时间：',time.asctime())
